<template>
  <nav class="navigation">
    <div class="nav-container">
      <div class="logo-section">
        <div class="logo">M</div>
        <div class="nav-title">管理系统</div>
      </div>

      <div class="nav-menu">
        <button class="nav-item" :class="{ active: currentPage === 'projects' }"
          @click="$emit('page-change', 'projects')">
          📊 项目管理
        </button>
        <button class="nav-item" :class="{ active: currentPage === 'data' }" @click="$emit('page-change', 'data')">
          🔗 数据整合中心
        </button>
        <button class="nav-item" :class="{ active: currentPage === 'alerts' }" @click="$emit('page-change', 'alerts')">
          ⚠️ 项目告警
        </button>
      </div>

      <div class="user-info">
        <div class="user-avatar">U</div>
        <span class="user-name">管理员</span>
        <button class="logout-btn" @click="handleLogout" title="退出登录">
          🚪
        </button>
      </div>
    </div>
  </nav>
</template>

<script setup lang="ts">
import { useAuth } from '../composables/useAuth'

interface Props {
  currentPage: 'projects' | 'data' | 'alerts'
}

defineProps<Props>()
defineEmits<{
  'page-change': [page: 'projects' | 'data' | 'alerts']
}>()

const { logout } = useAuth()

const handleLogout = () => {
  if (confirm('确定要退出登录吗？')) {
    logout()
    // 刷新页面以重新显示授权界面
    window.location.reload()
  }
}
</script>

<style scoped>
.navigation {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
}

.logo-section {
  display: flex;
  align-items: center;
}

.logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  margin-right: 15px;
}

.nav-title {
  font-size: 20px;
  font-weight: 600;
  color: #2d3748;
}

.nav-menu {
  display: flex;
  gap: 8px;
}

.nav-item {
  padding: 10px 20px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-item:hover {
  background: #f3f4f6;
  color: #374151;
}

.nav-item.active {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4fd1c7, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 14px;
}

.user-name {
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.logout-btn {
  padding: 8px 12px;
  border: none;
  background: #f3f4f6;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logout-btn:hover {
  background: #e5e7eb;
  transform: translateY(-1px);
}

@media (max-width: 768px) {
  .nav-container {
    padding: 0 20px;
  }

  .nav-menu {
    gap: 4px;
  }

  .nav-item {
    padding: 8px 12px;
    font-size: 13px;
  }

  .user-name {
    display: none;
  }

  .logout-btn {
    padding: 6px 8px;
    font-size: 14px;
  }
}
</style>